<template>
	<view id="activity">
		<mescroll-uni ref="mescrollRef" @init="mescrollInit" top="0" bottom="0" @down="downCallback" @up="upCallback">
			<view  class="materialList"  v-for="(item,index) in list" :key="index">
				<view class="content" v-html='item.content'></view>
				<view class="shareImg" v-if='item.src' >
					<image  :src="item.src" alt="" mode="widthFix"  @click='previewImg(item.src)' />
				</view>
				<view class="operation s-flex-r-b-c">
					<text>{{item.createTime}}</text>
					<text class="text" @click='shareImg(item.src,item.content)' >分享素材</text>
				</view>
			</view>
		</mescroll-uni>
		<uni-popup ref="share" type="share" safeArea backgroundColor="#fff">
			<view class="shareBox">
				<view class="shareDiv">
					<image src="../../static/index/wx.png" @click="wxShare(1)"/>
					<view>微信</view>
				</view>
				<view class="shareDiv">
					<image src="../../static/index/wx-circle.png" @click="wxShare(2)"/>
					<view>朋友圈</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js"
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				productIndex:0,
				productList:[],
				productID:'',
				list:[],
				shareImage:'',
				content:''
			}
		},
		mounted() {
			
		},
		methods: {
			//list
			upCallback(page) {
				this.httpClient.post('agents/manageApp/ky/getOaKeyImgList', {
					pageNum:page.num,
					pageSize:page.size
				}).then(res => {
					this.mescroll.endByPage(res.rows.length, res.total)
					if (page.num == 1) this.list = [];
					this.list = this.list.concat(res.rows);
				}).catch(() => {
					this.mescroll.endErr();
				})
			},
			//预览图片
			previewImg(imgUrl) {
				uni.previewImage({
					urls: [imgUrl ]
				})
			},
			//分享按钮
			shareImg(img,content){
				if(img){
					this.shareImage=img
					this.content=content
					this.$refs.share.open()
				}else{
					uni.showToast({
						icon: 'none',
						title: '素材中没有图片，无法分享'
					});
				}
			},
			//分享
			wxShare(i){
				let shareType=''
				let that=this
				if(i==1){
					shareType='WXSceneSession'//分享到微信
				}else if(i==2){
					shareType='WXSceneTimeline'//分享到朋友圈
				}else{
					uni.showToast({
						icon: 'none',
						title: '系统错误'
					})
					return
				}
				uni.setClipboardData({
					data: that.content,
					showToast:false,
					success: function() {
						uni.showToast({
							icon: 'none',
							title: '文字已复制，图片加载中...'
						})
					}
				});
				uni.share({
					provider: "weixin",
					scene: shareType,
					type: 2,
					imageUrl: that.shareImage,
					success: function (res) {
						uni.showToast({
							icon: 'none',
							title: '分享成功'
						})
					},
					fail: function (err) {
						console.log("fail:" + JSON.stringify(err));
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	#activity{
		.materialList{
			padding: 1rem;
			background: #fff;
			margin-bottom: 15rpx;
			.head{
				height: 3rem;
				display: flex;
				align-items: center;
				image{
					width: 3rem;
					height: 3rem;
					margin-right: 0.6rem;
				}
				.msg{
					font-size: 0.9rem;
				}
				.time{
					font-size: 0.8rem;
					color: #888;
				}
			}
			.content{
				margin:10rpx 0;
			}
			.shareImg{
				width:100%;
				image{
					width: 60%;
					margin-right: 3%;
				}
			}
			.operation{
				width: 100%;
				margin-top:15rpx;
				.text{
					border: 1px solid #eee;
					display: inline-block;
					padding: 0.3rem 1rem;
					font-size: 0.8rem;
					color: #fff;
					background: #3aacff;
					border-radius: 20px;
					margin-right: 0.4rem;
				}
			}
		}
		.shareBox{
			padding:30rpx;
			.shareDiv{
				width:100rpx;height:150rpx;display:inline-block;margin:20rpx;font-size:26rpx;text-align: center;
				image{
					width:100rpx;height:100rpx;
				}
			}
		}
	}
</style>
